package com.newcapec.news.servlet;

import com.google.gson.Gson;
import com.newcapec.news.dao.SysUserDao;
import com.newcapec.news.dao.impl.SysUserDaoImpl;
import com.newcapec.news.entity.SysUser;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: 获取用户信息
 * @Author: fujun
 * @Date : 2022/3/17 16:17
 * @Version : 1.0
 * @company 新开普电子股份有限公司
 */
public class GetUserByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("utf-8");
//        resp.setCharacterEncoding("utf-8");


        String uid=req.getParameter("uid");

        SysUserDao sysUserDao=new SysUserDaoImpl();
        if(uid!=null){
        SysUser user=sysUserDao.getUserById(Integer.parseInt(uid));


//        String res="{'id':" +user.getId()+",'name':'"+user.getName()+"','acct':'"+user.getAcct()+"','pwd':'"+user.getPwd()+"'"+
//                "}";


            Gson gson=new Gson();
        resp.getWriter().write(gson.toJson(user));
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
